﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using System.Data;
using Ext.Net;
using System.Configuration;
using Utilities;

namespace TCDC_System.UserControl
{
    public partial class UserManageAdd : System.Web.UI.UserControl
    {
        private tcdc_mst_usertype objUserType;
        private tcdc_mst_user objUser;

        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!X.IsAjaxRequest)
            {
                StoreUserType.DataSource = GetUserType();
                StoreUserType.DataBind();
            }
        }

        public void Show()
        {
            WindowUserManageAdd.Show();
        }

        protected void SaveUser(object sender, DirectEventArgs e)
        {
            objUser = new tcdc_mst_user();
            objUser.strConn = ConfigurationManager.AppSettings["ConnString"];
            objUser.user_type_id = Convert.ToInt32(cmbUserType.Text);
            objUser.username = txtUsername.Text;
            objUser.password = Cryptography.GetMd5Hash(txtPassword.Text);

            objUser.insertData(objUser);
            GridStore.DataSource = objUser.getByObject(new tcdc_mst_user());
            GridStore.DataBind();
            FormPanel1.Reset();
            WindowUserManageAdd.Hide();
        }

        protected DataTable GetUserType()
        {
            objUserType = new tcdc_mst_usertype();
            objUserType.strConn = ConfigurationManager.AppSettings["ConnString"];

            DataTable dt = objUserType.getByObject(new tcdc_mst_usertype());

            return dt;
        }

        public Store GridStore { get; set; }
    }
}